function _openDialogUserInfo($user_id){
	jQuery.post(BASE_URL+"admin/dataman/seller/user_information",{user_id:$user_id},function(response){
		jQuery('#dialog').html(response);
		jQuery('#dialog').dialog(
			{
				 width: 950,
				 resizable: true,
				 height:600,
				 title: 'User Information'  
			}
		);
	});
}

function _openDialogShowInfo($show_id){
	jQuery.post(BASE_URL+"admin/dataman/show/show_information",{show_id:$show_id},function(response){
		jQuery('#dialog').html(response);
		jQuery('#dialog').dialog(
			{
				 width: 950,
				 resizable: true,
				 height:600,
				 title: 'Show Information'  
			}
		);
	});
}

function _openDialogBidInfo($bid_id){
	jQuery.post(BASE_URL+"admin/dataman/show/bid_information",{bid_id:$bid_id},function(response){
		jQuery('#dialog').html(response);
		jQuery('#dialog').dialog(
			{
				 width: 950,
				 resizable: true,
				 height:600,
				 title: 'Bid Information'   
			}
		);
	});
}

function change_show_status($value, $show_id){
	jQuery.post(BASE_URL+"admin/dataman/show/change_show_status",{show_id:$show_id,status:$value},function(response){
		window.location.reload();
	});
}

function change_bid_status($value, $bid_id){
	jQuery.post(BASE_URL+"admin/dataman/show/change_bid_status",{bid_id:$bid_id,status:$value},function(response){
		window.document.location = response;
		//alert(response)
	});
}

function _delete_bid($bid_id){
	if(confirm("Are you sure you want to delete this? It cannot be undone.")){
		jQuery.post(BASE_URL+"admin/dataman/show/delete_bid",{bid_id:$bid_id},function(response){
			window.location.reload();
		});
	}
}

function _edit_bid($bid_id){
	jQuery.post(BASE_URL+"admin/dataman/show/edit_bid",{bid_id:$bid_id},function(response){
		jQuery('#dialog').html(response);
		jQuery('#dialog').dialog(
			{
				 width: 950,
				 resizable: true,
				 height:600,
				 title: 'Edit Bid Information'    
			}
		);
		
	});
}

function _delete($show_id){
	if(confirm("Are you sure you want to delete this? It cannot be undone.")){
		jQuery.post(BASE_URL+"admin/dataman/show/delete",{show_id:$show_id},function(response){
			window.location.reload();
		});
	}
}

function _edit($show_id){
	jQuery.post(BASE_URL+"admin/dataman/show/edit",{show_id:$show_id},function(response){
		jQuery('#dialog').html(response);
		jQuery('#dialog').dialog(
			{
				 width: 950,
				 resizable: true,
				 height:600,
				 title: 'Edit Show Information'    
			}
		);
		
	});
}


jQuery(document).ready(function() {
	jQuery("#submit_information").live("submit",function(e){
		e.preventDefault(); // <-- important
		var options = { 
			beforeSubmit:  validateB4SubmitShow,   
			success:       processAfterRespondingShow   
		};	
		jQuery(this).ajaxSubmit(options);
		return false;
	});
	
	jQuery("#submit_edit_bid").live("submit",function(e){
		e.preventDefault(); // <-- important
		var options = { 
			beforeSubmit:  validateB4SubmitBid,   
			success:       processAfterRespondingBid   
		};	
		jQuery(this).ajaxSubmit(options);
		return false;
	});
	
});
 
function validateB4SubmitShow(formData, jqForm, options){
	jQuery('#loader').show();
	var array_err = ['show_name_error', 'artist_error', 'bid_open_error', 'music_genre_error', 'speaker_profile_error', 'plays_musicals_error', 'period_error','bid_due_date_error', 'available_for_error', 'entourage_no_error', 'min_bid_error', 'additional_error', 'tech_rider_error', 'show_image_error', 'hospitality_rider_error'];
	for(i in array_err){
		jQuery('#'+array_err[i]).addClass('hidden');
	}
}

function processAfterRespondingShow(responseText, statusText, xhr, $form){
	
	jQuery('#loader').hide();
	var arr_res = responseText.split('#');
	if(arr_res[0] == 'err'){
		for(i in arr_res){
			jQuery('#'+arr_res[i]+'_error').removeClass('hidden');
		}
		alert("Error. Any fields are missing.");
	}else{
		jQuery('#dialog').dialog('close');
		window.location.reload();
	}
	
} 


jQuery(function() {
	jQuery( "#start_date" ).live('focus',function(){
		jQuery( this ).datepicker({
			changeMonth: true,
			changeYear: true,
			dateFormat: 'dd-MM-yy'
		});
	});
	jQuery( "#end_date" ).live('focus',function(){
		jQuery( this ).datepicker({
			changeMonth: true,
			changeYear: true,
			dateFormat: 'dd-MM-yy'
		});
	});
	jQuery( "#bid_due_date" ).live('focus',function(){
		jQuery( this ).datepicker({
			changeMonth: true,
			changeYear: true,
			dateFormat: 'dd-MM-yy'
		});
	});
	
	
	jQuery('#__private,#__commercial').live('click',function (){
		$_private = jQuery('#__private').attr('checked');
		$_commercial = jQuery('#__commercial').attr('checked');
		if($_private || $_commercial){
			 jQuery('#__public').attr('checked',false);
		}
	});
	
	jQuery('#__public').live('click',function(){
		$_public = jQuery('#__public').attr('checked');
		if($_public){
			jQuery('#__private').attr('checked',false);
			jQuery('#__commercial').attr('checked',false);
		}
	});
		
});
	
	




	
	
function validateB4SubmitBid(formData, jqForm, options){
	jQuery('#submit_bid_loader').show();
	$err = 0;
	jQuery('.required').each(function(i,o){
	   if( isEmpty( jQuery(this).val() ) ){
			jQuery(this).addClass('error');
			$err ++;
		}else{
			jQuery(this).removeClass('error');
		}
	});
	
	if( !isIntNumber( jQuery('#offer_price').val() ) || jQuery('#offer_price').val() < 0 ){
		jQuery('#offer_price').addClass('error');
		$err ++;
	}else{
		jQuery('#offer_price').removeClass('error');
	}
	
	if($err > 0){
		jQuery('#submit_bid_loader').hide();
		jQuery('#submit_bid_error').removeClass('hidden');
		return false;
	}
	jQuery('#submit_bid_error').addClass('hidden');
	return true;
}

function processAfterRespondingBid(responseText, statusText, xhr, $form){
	jQuery('#submit_bid_loader').hide();
	var arr_res = responseText.split('#');
	if(arr_res[0] == 'ok'){
		window.location.reload();
	}else{
		alert(responseText);
	}
}
	
function changeZone(positionId, value){
	jQuery.post(BASE_URI+"buyer/shows/ajax_changeZone",{value:value,positionId:positionId},function(response){
		jQuery('#'+positionId+" #country_slb").html(response);
		var firstValue = jQuery('#'+positionId+" #country_slb select").val();
		changeCountry(positionId, firstValue);
	});
}

function changeCountry(positionId, value){
	jQuery.post(BASE_URI+"buyer/shows/ajax_changeCountry",{value:value,positionId:positionId},function(response){
		jQuery('#'+positionId+" #city_slb").html(response);
	});
}

function addACity(){
	jQuery('#loader_add_a_city').removeClass("hidden");
	var currentItem = jQuery('#booking_zone .items').size();
	
	jQuery.post(BASE_URI+"buyer/shows/ajax_addBookingfor",{currentItem:currentItem},function(response){
		jQuery("#booking_zone").append(response);
		jQuery('#loader_add_a_city').addClass("hidden");
	});
}

function removeItem($position_id, $item_id){
	//jQuery("#remove_booking_item_"+$position_id).show();
	//jQuery.post(BASE_URI+"buyer/shows/removeBooking",{booking_id:$item_id},function(response){
	//	if(response == 'ok'){
			jQuery("#booking_zone #id_"+ $position_id).remove();
	//	}
	//})
}

jQuery(function() {
	jQuery('.removeitem').live('click',function(){
		$id= jQuery(this).attr('rel');
		jQuery("#booking_zone #"+ $id).remove();
	});
});	










